<?php

namespace app\model;

use think\Model;

class Withdraw extends Model
{

    protected $connection = 'mysql';

    protected $pk = 'id';

    protected $name = 'withdraw';

    static public function setpoundage($data)
    {
        $days = $data['days'];
        $amounts = $data['amounts'];
        $mo = $data['mo'];
        $Config = Config::getconfig($mo);
        $cscl =  Config::setcashservice($Config);
        $data['cscl'] = $cscl;
        $Config['cash_service_charge'] = (float) $Config['cash_service_charge'];

        if ($cscl[$days]['days']) {
            $Config['cash_service_charge'] = (float) $cscl[$days]['price'];
        }

        if (empty($Config['cash_service_charge'])) {
            $data['poundage'] = 0;
            $data['poundage_rate'] = $Config['cash_service_charge'];
            $data['actual_amounts'] = $amounts;
        } else {
            if (empty($cscl[$days]['calculate_method'])) {
                $data['poundage'] = round(($amounts * percent_to_num($Config['cash_service_charge'])), 2);

                if ($Config['cash_service_charge'] > 100) {
                    $is100 = 1;
                }
            } else {
                $data['poundage'] = $Config['cash_service_charge'];
            }

            if ($is100 == 1) {
                $data['poundage_rate'] = 0;
                $data['actual_amounts'] = $data['poundage'];
                $data['poundage'] = 0;
            } else {
                $data['poundage_rate'] = $data['poundage'];
                $data['actual_amounts'] = round(($amounts - $data['poundage']), 2);
            }
        }

        return $data;
    }
}
